<?php
/**
 * This file creates functions that make creating and
 * removing Widget Areas very simple.
 *
 * It also creates our default Sidebar, hooked to prodigy_after_content
 *
 * @author Nathan Rice
 * @package Prodigy
 **/

/**
 * This function registers a new widget area, and also inserts
 * the widget area (output by $function) at the $hook location, by $priority
 *
 * @param string $sidebar_name is the name of sidebar you want to add
 * @param string $sidebar_id is the ID of the sidebar you want to add
 * @param string $hook the action hook to which you want to hook the function
 * @param string $function the function that will create the widget area output
 * @param integer $priority the priority at which $function will be hooked to $hook
 *
 * @since 0.1
 */
function prodigy_create_widget_area($sidebar_name = null, $sidebar_id = null, $hook, $function, $priority = 10) {
	register_sidebar(array(
		'name' => $sidebar_name,
		'id' => $sidebar_id,
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h5 class="widgettitle">',
		'after_title' => '</h5>'
	));
	add_action($hook, $function, $priority);
}

/**
 * This function does the opposite of prodigy_create_widget_area()
 * It removes both the widget area, and unhooks $function from $hook.
 *
 * @param string $sidebar_name is the name of sidebar you want to add
 * @param string $sidebar_id is the ID of the sidebar you want to add
 * @param string $hook the action hook to which you want to hook the function
 * @param string $function the function that will create the widget area output
 * @param integer $priority the priority at which $function will be hooked to $hook
 *
 * @since 0.1
 */
function prodigy_remove_widget_area($sidebar_name, $sidebar_id, $hook, $function, $priority = 10) {
	unregister_sidebar($sidebar_id);
	remove_action($hook, $function, $priority);
}

/**
 * This is the "default" sidebar in Prodigy. It can easily
 * be removed by using prodigy_remove_widget_area()
 *
 * This is a good example of how to add your own Widget Areas
 *
 * @uses prodigy_create_widget_area()
 * @uses dynamic_sidebar()
 *
 * @since 0.1
 */
prodigy_create_widget_area('Sidebar', 'sidebar-1', 'prodigy_after_content', 'prodigy_default_sidebar', 11);
function prodigy_default_sidebar() {
	echo '<div id="sidebar">'."\n";
	if(!dynamic_sidebar('sidebar-1')) {
		echo '<div class="widget">'."\n";
		echo '<h5 class="widgettitle">This is a Widget Area</h5>'."\n";
		echo 'This entire sidebar is widgetized. The new Widget interface in WordPress 2.8 will make you very happy, so head on over and put some widgets in here!'."\n";
		echo '</div>'."\n";
	}
	echo '</div><!--end #sidebar-->'."\n";
}
?>